{
 "metadata": {
  "signature": "sha256:c6b0367ab48014d0a1bcd9fad878704dada5ae8d28bc55d67cda8a31d899e4a9"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Matplotlib: unfilled histograms\n",
      "======================================================================\n",
      "\n",
      "Here's some template code for plotting histograms that don't look like\n",
      "bar charts, but instead have only outlines (like IDL creates).\n",
      "\n",
      "First define a function that does the bulk of the heavy lifting."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "\n",
      "def histOutline(dataIn, *args, **kwargs):\n",
      "    (histIn, binsIn) = np.histogram(dataIn, *args, **kwargs)\n",
      "\n",
      "    stepSize = binsIn[1] - binsIn[0]\n",
      "\n",
      "    bins = np.zeros(len(binsIn)*2 + 2, dtype=np.float)\n",
      "    data = np.zeros(len(binsIn)*2 + 2, dtype=np.float)\n",
      "    for bb in range(len(binsIn)):\n",
      "        bins[2*bb + 1] = binsIn[bb]\n",
      "        bins[2*bb + 2] = binsIn[bb] + stepSize\n",
      "        if bb < len(histIn):\n",
      "            data[2*bb + 1] = histIn[bb]\n",
      "            data[2*bb + 2] = histIn[bb]\n",
      "\n",
      "    bins[0] = bins[1]\n",
      "    bins[-1] = bins[-2]\n",
      "    data[0] = 0\n",
      "    data[-1] = 0\n",
      "\n",
      "    return (bins, data)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Now we can make plots:"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Make some data to plot\n",
      "data = randn(500)\n",
      "\n",
      "figure(2, figsize=(10, 5))\n",
      "clf()\n",
      "\n",
      "##########\n",
      "#\n",
      "# First make a normal histogram\n",
      "#\n",
      "##########\n",
      "subplot(1, 2, 1)\n",
      "(n, bins, patches) = hist(data)\n",
      "\n",
      "# Boundaries\n",
      "xlo = -max(abs(bins))\n",
      "xhi = max(abs(bins))\n",
      "ylo = 0\n",
      "yhi = max(n) * 1.1\n",
      "\n",
      "axis([xlo, xhi, ylo, yhi])\n",
      "\n",
      "##########\n",
      "#\n",
      "# Now make a histogram in outline format\n",
      "#\n",
      "##########\n",
      "(bins, n) = histOutline(data)\n",
      "\n",
      "subplot(1, 2, 2)\n",
      "plot(bins, n, 'k-')\n",
      "axis([xlo, xhi, ylo, yhi])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Below you can find this functionality packaged up into histOutline.py"
     ]
    }
   ],
   "metadata": {}
  }
 ]
}